﻿using System.Collections.Generic;
using System.Linq;
using DynamicChart.Service.FunctionConversion;
using DynamicChart.Util;

namespace DynamicChart.Service.Step.GenerateSQL;

public class GenerateGroupStep : GenerateAbstractSQLStep
{
    public GenerateGroupStep(ISqlFunctionAdapter adapter) : base(adapter)
    {
    }
    
    public override void Process(IDictionary<string, object> data, IDictionary<string, string> res)
    {
        var groupFields = DataProcessor.EnumerateFields(data)
            .Select(t => CreateField(t.Entity, $"{t.TableKey}.{t.ColumnKey}", "PolymerizationMode"))
            .Where(f => !string.IsNullOrEmpty(f))
            .ToList();

        res["group"] = string.Join(", ", groupFields);
    }
}